package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.Remarks;
import com.ruoyi.training.service.IRemarksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 备注Controller
 *
 * @author hcc
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/remarks")
public class RemarksController extends BaseController
{
    @Autowired
    private IRemarksService remarksService;

    /**
     * 查询备注列表
     */
    @RequiresPermissions("training:remarks:list")
    @GetMapping("/list")
    public TableDataInfo list(Remarks remarks)
    {
        startPage();
        List<Remarks> list = remarksService.selectRemarksList(remarks);
        return getDataTable(list);
    }

    /**
     * 查询备注历史列表
     */
    @RequiresPermissions("training:remarks:list")
    @GetMapping("/listHistory")
    public TableDataInfo listHistory(Remarks remarks)
    {
        startPage();
        List<Remarks> list = remarksService.selectRemarksHistoryList(remarks);
        return getDataTable(list);
    }

    /**
     * 导出备注列表
     */
    @RequiresPermissions("training:remarks:export")
    @Log(title = "备注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Remarks remarks)
    {
        List<Remarks> list = remarksService.selectRemarksList(remarks);
        ExcelUtil<Remarks> util = new ExcelUtil<Remarks>(Remarks.class);
        util.exportExcel(response, list, "备注数据");
    }

    /**
     * 获取备注详细信息
     */
    @RequiresPermissions("training:remarks:query")
    @GetMapping(value = "/{remarkId}")
    public AjaxResult getInfo(@PathVariable("remarkId") String remarkId)
    {
        return success(remarksService.selectRemarksByRemarkId(remarkId));
    }

    /**
     * 查询备注通过外键id
     */
    @RequiresPermissions("training:remarks:query")
    @GetMapping("/getRemark")
    public AjaxResult getRemark(Remarks remarks)
    {
        return success(remarksService.selectRemarksByForeignId(remarks.getForeignId(),remarks.getRemarkType()));
    }

    /**
     * 新增备注
     */
    @RequiresPermissions("training:remarks:add")
    @Log(title = "备注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Remarks remarks)
    {
        return toAjax(remarksService.insertRemarks(remarks));
    }

    /**
     * 修改备注
     */
    @RequiresPermissions("training:remarks:edit")
    @Log(title = "备注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Remarks remarks)
    {
        return toAjax(remarksService.updateRemarks(remarks));
    }

    /**
     * 删除备注
     */
    @RequiresPermissions("training:remarks:remove")
    @Log(title = "备注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{remarkIds}")
    public AjaxResult remove(@PathVariable String[] remarkIds)
    {
        return toAjax(remarksService.deleteRemarksByRemarkIds(remarkIds));
    }
}
